package com.wry.sharding.controller;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

import com.wry.sharding.dao.OmsOrder;
import com.wry.sharding.dao.OmsOrderGoodsItem;
import com.wry.sharding.mapper.OmsOrderGoodsItemMapper;
import com.wry.sharding.service.OmsOrderGoodsItemService;
import com.wry.sharding.service.OmsOrderService;
import com.wry.sharding.utils.TimeUtil;
import lombok.Data;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <h1>  <h1>
 *
 * @author wry
 * @since 2025/1/13 18:58
 */
@RequestMapping("order")
@RestController
public class OrderController {

    @Resource
    private OmsOrderService orderService;
    @Resource
    private OmsOrderGoodsItemService omsOrderGoodsItemService;

    @GetMapping("test1")
    public String insert1(@RequestParam("orderNumber") String orderNumber) {
        final LocalDateTime localDateTime = TimeUtil.toLocalDateTime("2024-12-14 15:09:16");
        OmsOrder omsOrder = new OmsOrder();
        omsOrder.setOrderNumber(orderNumber);
        omsOrder.setNewOrderNumber("");
        omsOrder.setOriginalOrderNumber("989561316513213");
        omsOrder.setShopId(0);
        omsOrder.setPlatformName("抖音小店");
        omsOrder.setShopName("");
        omsOrder.setOrderStatus(0);
        omsOrder.setOrderType(0);
        omsOrder.setOrderSourceType(0);
        omsOrder.setOrderCreateDate(LocalDateTime.now());
        omsOrder.setPayStatus(0);
        omsOrder.setPayNumber("");
        omsOrder.setPayTime(localDateTime);
        omsOrder.setPayType(0);
        omsOrder.setPayAccount("");
        omsOrder.setReceivePayAccount("");
        omsOrder.setPayMoney(new BigDecimal("0"));
        omsOrder.setPayDiscountMoney(new BigDecimal("0"));
        omsOrder.setPayRefundMoney(new BigDecimal("0"));
        omsOrder.setPayPostageMoney(new BigDecimal("0"));
        omsOrder.setAdjustFree(new BigDecimal("0"));
        omsOrder.setPaySettleType(0);
        omsOrder.setGoodsQuantity(0);
        omsOrder.setOrderMoney(new BigDecimal("0"));
        omsOrder.setReceiverName("");
        omsOrder.setReceiverPostcode("");
        omsOrder.setReceiverPhone("");
        omsOrder.setProvinceId(0);
        omsOrder.setReceiverProvince("");
        omsOrder.setCityId(0);
        omsOrder.setReceiverCity("");
        omsOrder.setDistrictsId(0L);
        omsOrder.setReceiverDistricts("");
        omsOrder.setReceiverAddress("");
        omsOrder.setTownId(0L);
        omsOrder.setReceiverTown("");
        omsOrder.setExpressId(0);
        omsOrder.setExpressName("");
        omsOrder.setExpressCode("");
        omsOrder.setExpressNumber("");
        omsOrder.setExpressExecuteFlag(0);
        omsOrder.setMemberName("");
        omsOrder.setMemberRemark("");
        omsOrder.setMemberMessage("");
        omsOrder.setResponderRemark("");
        omsOrder.setDeliveryStatus(0);
        omsOrder.setDeliveryDate(LocalDateTime.now());
        omsOrder.setWarehouseId(0);
        omsOrder.setWarehouseName("");
        omsOrder.setWarehouseSubmitStatus(0);
        omsOrder.setWarehouseOutDate(LocalDateTime.now());
        omsOrder.setTagId(0);
        omsOrder.setTagName("");
        omsOrder.setBookType(0);
        omsOrder.setAuditId(0);
        omsOrder.setAuditOr("");
        omsOrder.setAuditAt(LocalDateTime.now());
        omsOrder.setSubmitDate(LocalDateTime.now());
        omsOrder.setDownloadDate(LocalDateTime.now());
        omsOrder.setDealDate(LocalDateTime.now());
        omsOrder.setActivateDate(LocalDateTime.now());
        omsOrder.setFreezedAt(LocalDateTime.now());
        omsOrder.setFreezeReason("");
        omsOrder.setCancelReasonId(0);
        omsOrder.setReviewExtraStatus("");
        omsOrder.setOutOfStock("");
        omsOrder.setIsSpecialRefund("");
        omsOrder.setCreatedAt(LocalDateTime.now());
        omsOrder.setOaid("");
        omsOrder.setHandleOrderType("");
        omsOrder.setAutoHandleType("");
        omsOrder.setExpressTransportStatus("");
        omsOrder.setExpressTransportDateTime(LocalDateTime.now());
        omsOrder.setOrderTotalWeight(new BigDecimal("0"));
        omsOrder.setExpressPlatform("");
        omsOrder.setExpressPlatformId(0);
        omsOrder.setCarrierCode("");
        omsOrder.setCarrierName("");
        omsOrder.setBuyerOpenUid("");
        omsOrder.setExpressCostEstimate(new BigDecimal("0"));
        omsOrder.setChargingWeightEstimate(new BigDecimal("0"));
        omsOrder.setFrsExpressCost(new BigDecimal("0"));
        omsOrder.setExpressCostEstimateDetail("");
        omsOrder.setCollectionDate(LocalDateTime.now());
        omsOrder.setSigningDate(LocalDateTime.now());
        omsOrder.setPrintOrderDate(LocalDateTime.now());
        omsOrder.setBrand("");
        orderService.save(omsOrder);
        for (int i = 1; i <= 3; i++) {
            OmsOrderGoodsItem omsOrderGoodsItem = new OmsOrderGoodsItem();
            omsOrderGoodsItem.setPayTime(omsOrder.getPayTime());
            omsOrderGoodsItem.setOriginalOrderNumber("setOriginalOrderNumber");
            omsOrderGoodsItem.setOriginalSubOrderNumber("fdfdfdfdf");
            omsOrderGoodsItem.setGoodsId(0);
            omsOrderGoodsItem.setOrderNumber(orderNumber);
            omsOrderGoodsItem.setGoodsPlatformId("");
            omsOrderGoodsItem.setGoodsBarCode("");
            omsOrderGoodsItem.setGoodsMkCode("");
            omsOrderGoodsItem.setGoodsNumber("");
            omsOrderGoodsItem.setGoodsItemCode("");
            omsOrderGoodsItem.setGoodsName("货品-"+i);
            omsOrderGoodsItem.setPicPath("");
            omsOrderGoodsItem.setGoodsStatus("");
            omsOrderGoodsItem.setGoodsSku(0);
            omsOrderGoodsItem.setGoodsSpecification("");
            omsOrderGoodsItem.setGoodsQuantity(0);
            omsOrderGoodsItem.setGoodsUnit("");
            omsOrderGoodsItem.setGoodsPrice(new BigDecimal("0"));
            omsOrderGoodsItem.setGoodsTotalPrice(new BigDecimal("0"));
            omsOrderGoodsItem.setGoodsRemark("");
            omsOrderGoodsItem.setGoodsBatchNumber("");
            omsOrderGoodsItem.setGoodsBatchQuantity(0);
            omsOrderGoodsItem.setGoodsProductionDate(LocalDateTime.now());
            omsOrderGoodsItem.setGoodsExpiredDate(LocalDateTime.now());
            omsOrderGoodsItem.setRefundStatus(0);
            omsOrderGoodsItem.setNetContent(new BigDecimal("0"));
            omsOrderGoodsItem.setNetContentUnit("");
            omsOrderGoodsItem.setGoodsDiscountPrice(new BigDecimal("0"));
            omsOrderGoodsItem.setGoodsPayMoney(new BigDecimal("0"));
            omsOrderGoodsItem.setGoodsPartMjzDiscount(new BigDecimal("0"));
            omsOrderGoodsItem.setGoodsDiscountTotalPrice(new BigDecimal("0"));
            omsOrderGoodsItem.setGoodsPayTotalMoney(new BigDecimal("0"));
            omsOrderGoodsItem.setGoodsPartMjzTotalDiscount(new BigDecimal("0"));
            omsOrderGoodsItem.setIsGift(0);
            omsOrderGoodsItem.setWeight(new BigDecimal("0"));
            omsOrderGoodsItem.setCreatedAt(LocalDateTime.now());
            omsOrderGoodsItem.setRefundTag("");
            omsOrderGoodsItemService.save(omsOrderGoodsItem);
        }
        return "ok";
    }

    @Resource
    private OmsOrderGoodsItemMapper omsOrderGoodsItemMapper;

    @Data
    public static class OrderGoodsInfo {
        private String orderNumber;
        private String goodsName;
        private BigDecimal payMoney;
    }
    @GetMapping("query1")
    public Object query(@RequestParam("orderNumber") String orderNumber){
        final LocalDateTime dateTime = TimeUtil.toLocalDateTime("2024-12-14 15:09:16");
        List<OrderGoodsInfo> infoList = omsOrderGoodsItemMapper.query1(orderNumber, dateTime);
        return infoList;
    }
}
